<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>

<p id="p" style="width: 10em;">
  This paragraph contains two lines of text.
</p>

<p id="description"></p>
<pre id="tree"></pre>
<div id="console"></div>

<script>

async_test((t) => {
    var notificationCalled = false;

    var axParagraph = accessibilityController.accessibleElementById('p');
    var axStaticText = axParagraph.childAtIndex(0);
    assert_equals(axStaticText.childrenCount, 2);

    var axInlineBefore0 = axStaticText.childAtIndex(0);
    assert_equals(axInlineBefore0.name, 'This paragraph contains ');
    var axInlineBefore1 = axStaticText.childAtIndex(1);
    assert_equals(axInlineBefore1.name, 'two lines of text.');

    // Modify the text.
    var p = document.getElementById("p");
    p.firstChild.data = p.innerText + ' One more sentence.';

    // Wait for a notification on the element before checking the new state.
    axStaticText.addNotificationListener(t.step_func((notification) => {
        // The notification might be called before or after the document
        // load event. This test allows either cases and ignore subsequent
        // notifications after the first notification.
        if (notificationCalled) {
            return;
        }
        // Make sure the inline text boxes changed.
        assert_equals(axStaticText.childrenCount, 3);
        var axInlineAfter0 = axStaticText.childAtIndex(0);
        assert_equals(axInlineAfter0.name, 'This paragraph contains ');
        var axInlineAfter1 = axStaticText.childAtIndex(1);
        assert_equals(axInlineAfter1.name, 'two lines of text. One ');
        var axInlineAfter2 = axStaticText.childAtIndex(2);
        assert_equals(axInlineAfter2.name, 'more sentence.');

        // Make sure the old object pointing to the second text box is no longer valid.
        assert_equals(axInlineBefore1.name, '');

        notificationCalled = true;
        t.done();
    }));
}, "Tests that accessible inline text boxes update when a static text node changes.");


</script>

</body>
</html>
